<?php
class ModelCatalogProductTpl extends Model {
	public function getTemplates($filter, &$total) {
		$sql = "SELECT template_id, title, status FROM `@@product_template`";
		if ($filter) {
			if ($filter->get('filter_status') !== null) {
				$sql .= " WHERE status = " . $filter->get('filter_status');
			}
			$sql .= $filter->limit();
		}
		
		$total = $this->db->queryCount($sql);
		$query = $this->db->query($sql);
		return $query->rows;
	}
	
	public function getTemplate($template_id) {
		return $this->db->get('product_template', array('template_id' => $template_id));
	}
	
	public function addTemplate($data) {
		return $this->db->insert('product_template', $data);
	}
	
	public function updateTemplate($template_id, $data) {
		return $this->db->update('product_template', $data, array('template_id' => $template_id));
	}
	
	public function deleteTemplate($template_ids) {
		if (is_array($template_ids))
			$template_ids = implode(',', $template_ids);
		return $this->db->runSql("DELETE FROM `@@product_template` WHERE template_id IN ($template_ids)");
	}
}
?>